<template>
<h1>员工列表练习</h1>
  <input type="text" placeholder="请输入员工姓名" v-model="u.name">
  <input type="text" placeholder="请输入员工工资" v-model="u.sal">
  <input type="text" placeholder="请输入员工岗位" v-model="u.job">
  <hr>
  <button @click="add()">点我添加</button>
  <hr>
  <table border="1px">
    <tr>
      <th>编号</th>
      <th>员工姓名</th>
      <th>员工工资</th>
      <th>员工岗位</th>
    </tr>
    <tr v-for="(emp,i) in arr">
      <td>{{i+1}}</td>
      <td>{{emp.name}}</td>
      <td>{{emp.sal}}</td>
      <td>{{emp.job}}</td>
    </tr>
  </table>
</template>

<script setup>
import {ref} from "vue";

const arr=ref([]);
const u=ref({name:'',sal:'',job:''});
const add=()=>{
  let newEmp={
    name:u.value.name,
    sal:u.value.sal,
    job:u.value.job
  }
  arr.value.push(newEmp);
  u.value={name:'',sal:'',job:''};
}

</script>

<style scoped>

</style>